package edu.hawaii.duedates.wicket;

import static org.junit.Assert.assertEquals;
import org.apache.wicket.util.tester.FormTester;
import org.apache.wicket.util.tester.WicketTester;
import org.junit.Test;

/**
 * Test Cases for the DisplayPage class.
 * @author John Ly
 *
 */

public class TestAllPages {

  /**
   * Tests the display page, logging in with a dummy account in the xml file.
   */
  @Test
  public void testAllPages() {
    WicketTester tester = new WicketTester(new DueDatesWebApp());
    tester.startPage(Index.class);
    tester.assertRenderedPage(Index.class);

    // Fill out the login form.
    FormTester formTester = tester.newFormTester("form");
    formTester.setValue("Email", "test");
    formTester.setValue("Password", "test");
    formTester.submit("Submit");
    // Should be successful login.
    tester.assertRenderedPage(DisplayPage.class);
    // Check contents on DisplayPage.
    tester.assertLabel("Welcome", "Welcome test");
    tester.assertContains("My Libraries");
    tester.assertContains("All Libraries");    
       
    /*------------- Alerts Page ------------------ */
    tester.clickLink("alertPageLink");
    tester.assertRenderedPage(AlertPage.class);
    tester.assertContains("test");    
    
    
    /* ------------ Display Page ---------------- */
    tester.clickLink("displayPageLink");
    tester.assertRenderedPage(DisplayPage.class);
    tester.clickLink("sortDateLink");
    tester.assertRenderedPage(DisplayPage.class);
    tester.clickLink("sortLibraryLink");
    tester.assertRenderedPage(DisplayPage.class); 
    FormTester ft = tester.newFormTester("topForm");
    ft.submit("updateAll");
    tester.assertRenderedPage(DisplayPage.class);
    
    /* ------------ Sign Out -------------------- */
    tester.clickLink("signOut");
    tester.assertRenderedPage(Index.class);
    
    assertEquals("Random test for PMD", 2, 2);
    
  }
}
